<?php
/**
 *无权限验证、无登录验证公共基础类
 * User: raisound
 * Date: 2021/10/13
 */

namespace app\api\controller;
use app\BaseController;
use think\exception\HttpResponseException;

class Base extends BaseController
{
    public function initialize()
    {
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: X-Token,Content-Type, Content-Length, Authorization, Accept, X-Requested-With, Current-Page');
        header('Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE,PUT');
        parent::initialize();
    }

    public function returnResult(...$args){
        throw new HttpResponseException(returnResult(...$args));
    }

    public static function error($info,$mark){
        try{
            errorLog($mark, $info->getMessage(), __FILE__."=>".$info->getLine(),true);
            if(is_debug()){
                $message = $info->getMessage();
            }else{
                $message = config("config.describe.error");
            }
            return returnResultExit(config("config.code.error"),$message);
        }catch (\Exception $e){
            errorLog('BaseBus.error', $e->getMessage());
            return returnResult(config("config.code.error"),config("config.describe.error"));
        }
    }
}
